
use "$clean/clean_all.dta", clear
   
loc experiments " posterior_comp posterior_comp "
		   
		   
preserve

clear all
eststo clear
estimates drop _all

set obs 10
qui gen x = 1
qui gen y = 1

loc columns = 0

foreach choice in `experiments' `experiments' `experiments' {

    loc ++columns
    qui eststo col`columns': reg x y

}

restore


/* Statistics */

loc colnum = 1
loc colnames ""


foreach choice in posterior_comp {

/* Statistics */

 xi:  reg `choice' treatment , vce(r)
	estadd loc thisstat6 = `e(N)': col`colnum'
    sigstar treatment, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col`colnum'
    estadd loc thisstat3 = "`r(sestar)'": col`colnum'
	
	qui sum `choice'  if  treatment==0
    estadd scalar thisstat5 = r(mean): col`colnum'

	estadd local thisstat7 = "No": col`colnum'
	
    loc ++colnum
    loc colnames "`colnames' `"`: var la `choice''"'"

	
 xi: qui reg `choice' treatment $contr , vce(r)
	estadd loc thisstat6 = `e(N)': col`colnum'
    sigstar treatment, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col`colnum'
    estadd loc thisstat3 = "`r(sestar)'": col`colnum'
	
	qui sum `choice'  if  treatment==0
    estadd scalar thisstat5 = r(mean): col`colnum'

	estadd local thisstat7 = "Yes": col`colnum'
	
	
    loc ++colnum
    loc colnames "`colnames' `"`: var la `choice''"'"

*** Underestimators ***
	
 xi: qui reg `choice' treatment if prior_comp<=57 , vce(r)
	estadd loc thisstat6 = `e(N)': col`colnum'
    sigstar treatment, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col`colnum'
    estadd loc thisstat3 = "`r(sestar)'": col`colnum'
	
	qui sum `choice'  if  treatment==0  & prior_comp<=57
    estadd scalar thisstat5 = r(mean): col`colnum'

	estadd local thisstat7 = "No": col`colnum'
	
	
    loc ++colnum
    loc colnames "`colnames' `"`: var la `choice''"'"
	
	
 xi: qui reg `choice' treatment $contr if prior_comp<=57, vce(r)
	estadd loc thisstat6 = `e(N)': col`colnum'
    sigstar treatment, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col`colnum'
    estadd loc thisstat3 = "`r(sestar)'": col`colnum'
	
	qui sum `choice'  if  treatment==0 & prior_comp<=57
    estadd scalar thisstat5 = r(mean): col`colnum'

	estadd local thisstat7 = "Yes": col`colnum'
	
	
    loc ++colnum
    loc colnames "`colnames' `"`: var la `choice''"'"
	
*** overestimators ***
	
 xi: qui reg `choice' treatment if prior_comp>57 , vce(r)
	estadd loc thisstat6 = `e(N)': col`colnum'
    sigstar treatment, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col`colnum'
    estadd loc thisstat3 = "`r(sestar)'": col`colnum'
	
	qui sum `choice'  if  treatment==0  & prior_comp>57
    estadd scalar thisstat5 = r(mean): col`colnum'

	estadd local thisstat7 = "No": col`colnum'
	
	
    loc ++colnum
    loc colnames "`colnames' `"`: var la `choice''"'"
	
	
 xi: qui reg `choice' treatment $contr if prior_comp>57, vce(r)
	estadd loc thisstat6 = `e(N)': col`colnum'
    sigstar treatment, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col`colnum'
    estadd loc thisstat3 = "`r(sestar)'": col`colnum'
	
	qui sum `choice'  if  treatment==0  & prior_comp>57
    estadd scalar thisstat5 = r(mean): col`colnum'

	estadd local thisstat7 = "Yes": col`colnum'
	
	
    loc ++colnum
    loc colnames "`colnames' `"`: var la `choice''"'"	
	

	}
	

	

loc rowlabels " "   "Treatment" " " " " "\midrule Control mean" "Observations" "\hline Controls"

loc rowstats ""

forval i = 1/7 {
    loc rowstats "`rowstats' thisstat`i'"
}



esttab * using "$tables/Table_A7.tex", replace cells(none) booktabs nonotes compress alignment(c) ///
 nogap noobs nobaselevels label stats(`rowstats', labels("`rowlabels'") ///
 fmt( 3 3 3 3 3 3 3 0 0 0 0 0 0 3 3 3 3 3 3 3 0  3 3 3 3 3 3 3 3 3 3 3 3 0 )) nomtitle ///
   mgroups(  "Full sample" "Underestimators" "Overestimators",  pattern(1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
